package org.linlinjava.litemall.db.controller;



import org.linlinjava.litemall.db.service.LitemallTagServiceImpl;
import org.linlinjava.litemall.db.domain.LitemallTag;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.linlinjava.litemall.core.common.PageResult;
import org.linlinjava.litemall.core.common.Result;
import org.linlinjava.litemall.core.common.StatusCode;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 商品标签 前端控制器
 * </p>
 *
 * @author xjp
 * @since 2020-06-11
 */
@RestController
@RequestMapping("/litemallTag")
public class LitemallTagController {

    @Autowired
    public LitemallTagServiceImpl litemallTagService;

    @ApiOperation(value = "新增")
    @PostMapping("/save")
    public Result save(@RequestBody LitemallTag litemallTag){
        litemallTagService.save(litemallTag);
        return new Result(StatusCode.SUCCESS,"保存成功");
    }

    @ApiOperation(value = "根据id删除")
    @PostMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Long id){
        litemallTagService.removeById(id);
        return new Result(StatusCode.SUCCESS,"删除成功");
    }

    @ApiOperation(value = "条件查询")
    @PostMapping("/get")
    public Result list(@RequestBody LitemallTag litemallTag){
        List<LitemallTag> litemallTagList = litemallTagService.list(new QueryWrapper<>(litemallTag));
        return new Result(StatusCode.SUCCESS,"查询成功",litemallTagList);
    }

    @ApiOperation(value = "列表（分页）")
    @GetMapping("/list/{pageNum}/{pageSize}")
    public Object list(@PathVariable("pageNum")Long pageNum, @PathVariable("pageSize")Long pageSize){
        IPage<LitemallTag> page = litemallTagService.page(
                new Page<>(pageNum, pageSize),
                null);
        return new Result(StatusCode.SUCCESS,"查询成功",new PageResult<>(page.getTotal(),page.getRecords()));
    }

    @ApiOperation(value = "详情")
    @GetMapping("/get/{id}")
    public Result get(@PathVariable("id") Long id){
        LitemallTag litemallTag = litemallTagService.getById(id);
        return new Result(StatusCode.SUCCESS,"查询成功",litemallTag);
    }

    @ApiOperation(value = "根据id修改")
    @PostMapping("/update/{id}")
    public Result update(@PathVariable("id") Long id, @RequestBody LitemallTag litemallTag){
        litemallTag.setId(id);
        litemallTagService.updateById(litemallTag);
        return new Result(StatusCode.SUCCESS,"更新成功");
    }


}
